package cn.myj2c.executor.values;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

public class JavaObject extends JavaValue {
    private Object value;
    private String type;
    public static final Map<String, Function<Object, Object>> patchClasses = new HashMap<>();

    public JavaObject(Object value, String type) {
        this.value = value;
        this.type = type;
    }

    public JavaObject(String type) {
        this.type = type;
    }

    @Override
    public Object value() {
        return this.value;
    }

    public JavaObject copy() {
        return this;
    }

    public void initialize(Object value) {
    	if(patchClasses.containsKey(type))
    		this.value = patchClasses.get(type).apply(value);
    	else
    		this.value = value;
    }

    public String type() {
        return this.type;
    }
    public String toString() {
        return "JavaObject@" + Integer.toHexString(System.identityHashCode(this)) + "(value=" + value + ", type=" + type + ")";
    }
}
